using SM.core;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSBH.func
{
	public class frmInOutMoneyBill : Form
	{
		private IContainer components = null;
		private Button btnClose;
		private DataGridView dgvBill;
		private GroupBox groupBox3;
		private TextBox txtCountItem;
		private Button btnDel;
		private Button btnPrint;
		private Button btnSave;
		private Button btnEdit;
		private Button btnAdd;
		private GroupBox groupBox1;
		private TextBox txtID;
		private Label label1;
		private TextBox txtName;
		private Label label2;
		private Button btnSearch;
		private TextBox txtMoney;
		private Label label3;
		private TextBox txtNote;
		private Label label4;
		private Label label5;
		private DateTimePicker txttoDay;
		private Label label6;
		private DateTimePicker txtfromDay;
		private TextBox txtObjectSearch;
		private Label label7;
		private Button btnSeeAll;
		private Button btnObjectSearch;
		private Label label8;
		private DateTimePicker dtpTimeBill;
		private Label lblType;
		private TextBox txtFullName;
		private Label lblDayInOut;
		private DateTimePicker dtpExecuteDate;
		private Label lblFullNameInOut;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn7;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
		private DataGridViewTextBoxColumn Column1;
		private DataGridViewTextBoxColumn Column10;
		private DataGridViewTextBoxColumn Column13;
		private DataGridViewTextBoxColumn Column11;
		private DataGridViewTextBoxColumn Column14;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn Column3;
		private DataGridViewTextBoxColumn Column4;
		private Func objFunc = new Func();
		private InOutBill objInOutBill = new InOutBill();
		public string Type = "";
		public string currObjectID = "";
		public string userName = "";
		public string fullName = "";
		public string currUserName = "";
		private bool noAllowOtherEditBill = false;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmInOutMoneyBill));
			this.btnClose = new Button();
			this.dgvBill = new DataGridView();
			this.dataGridViewTextBoxColumn7 = new DataGridViewTextBoxColumn();
			this.dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
			this.Column1 = new DataGridViewTextBoxColumn();
			this.Column10 = new DataGridViewTextBoxColumn();
			this.Column13 = new DataGridViewTextBoxColumn();
			this.Column11 = new DataGridViewTextBoxColumn();
			this.Column14 = new DataGridViewTextBoxColumn();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.Column3 = new DataGridViewTextBoxColumn();
			this.Column4 = new DataGridViewTextBoxColumn();
			this.groupBox3 = new GroupBox();
			this.btnSeeAll = new Button();
			this.btnObjectSearch = new Button();
			this.txtObjectSearch = new TextBox();
			this.label7 = new Label();
			this.label5 = new Label();
			this.txttoDay = new DateTimePicker();
			this.label6 = new Label();
			this.txtfromDay = new DateTimePicker();
			this.txtCountItem = new TextBox();
			this.btnDel = new Button();
			this.btnPrint = new Button();
			this.btnSave = new Button();
			this.btnEdit = new Button();
			this.btnAdd = new Button();
			this.groupBox1 = new GroupBox();
			this.lblFullNameInOut = new Label();
			this.dtpExecuteDate = new DateTimePicker();
			this.txtFullName = new TextBox();
			this.lblDayInOut = new Label();
			this.label8 = new Label();
			this.dtpTimeBill = new DateTimePicker();
			this.txtNote = new TextBox();
			this.label4 = new Label();
			this.txtMoney = new TextBox();
			this.label3 = new Label();
			this.btnSearch = new Button();
			this.txtName = new TextBox();
			this.label2 = new Label();
			this.txtID = new TextBox();
			this.label1 = new Label();
			this.lblType = new Label();
			((ISupportInitialize)this.dgvBill).BeginInit();
			this.groupBox3.SuspendLayout();
			this.groupBox1.SuspendLayout();
			base.SuspendLayout();
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(796, 567);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(97, 26);
			this.btnClose.TabIndex = 18;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.dgvBill.AllowUserToAddRows = false;
			this.dgvBill.AllowUserToDeleteRows = false;
			this.dgvBill.AllowUserToOrderColumns = true;
			this.dgvBill.AllowUserToResizeColumns = false;
			this.dgvBill.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvBill.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvBill.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvBill.BackgroundColor = Color.White;
			this.dgvBill.BorderStyle = BorderStyle.Fixed3D;
			this.dgvBill.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvBill.Columns.AddRange(new DataGridViewColumn[]
			{
				this.dataGridViewTextBoxColumn7,
				this.dataGridViewTextBoxColumn1,
				this.Column1,
				this.Column10,
				this.Column13,
				this.Column11,
				this.Column14,
				this.Column2,
				this.Column3,
				this.Column4
			});
			this.dgvBill.Cursor = Cursors.Hand;
			this.dgvBill.EnableHeadersVisualStyles = false;
			this.dgvBill.Location = new System.Drawing.Point(7, 62);
			this.dgvBill.MultiSelect = false;
			this.dgvBill.Name = "dgvBill";
			this.dgvBill.ReadOnly = true;
			this.dgvBill.RowHeadersVisible = false;
			this.dgvBill.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle2.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvBill.RowsDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvBill.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvBill.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvBill.Size = new Size(886, 342);
			this.dgvBill.TabIndex = 6;
			this.dgvBill.CellClick += new DataGridViewCellEventHandler(this.dgvBill_CellClick);
			this.dgvBill.CellEnter += new DataGridViewCellEventHandler(this.dgvBill_CellEnter);
			this.dataGridViewTextBoxColumn7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewTextBoxColumn7.DataPropertyName = "CreateDate";
			dataGridViewCellStyle3.Format = "D";
			dataGridViewCellStyle3.NullValue = null;
			this.dataGridViewTextBoxColumn7.DefaultCellStyle = dataGridViewCellStyle3;
			this.dataGridViewTextBoxColumn7.HeaderText = "Ngày lập";
			this.dataGridViewTextBoxColumn7.MinimumWidth = 90;
			this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
			this.dataGridViewTextBoxColumn7.ReadOnly = true;
			this.dataGridViewTextBoxColumn7.Width = 90;
			this.dataGridViewTextBoxColumn1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewTextBoxColumn1.DataPropertyName = "ID";
			this.dataGridViewTextBoxColumn1.HeaderText = "Hoá đơn";
			this.dataGridViewTextBoxColumn1.MinimumWidth = 120;
			this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
			this.dataGridViewTextBoxColumn1.ReadOnly = true;
			this.dataGridViewTextBoxColumn1.Width = 120;
			this.Column1.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column1.DataPropertyName = "objectName";
			this.Column1.HeaderText = "Đối tượng";
			this.Column1.MinimumWidth = 160;
			this.Column1.Name = "Column1";
			this.Column1.ReadOnly = true;
			this.Column10.DataPropertyName = "TotalMoney";
			dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle4.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle4.Format = "N0";
			dataGridViewCellStyle4.NullValue = "0";
			this.Column10.DefaultCellStyle = dataGridViewCellStyle4;
			this.Column10.HeaderText = "Tổng tiền";
			this.Column10.MinimumWidth = 120;
			this.Column10.Name = "Column10";
			this.Column10.ReadOnly = true;
			this.Column10.Width = 120;
			this.Column13.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column13.DataPropertyName = "Note";
			this.Column13.HeaderText = "Diễn giải";
			this.Column13.MinimumWidth = 200;
			this.Column13.Name = "Column13";
			this.Column13.ReadOnly = true;
			this.Column13.Width = 200;
			this.Column11.DataPropertyName = "TypeInput";
			this.Column11.HeaderText = "TypeInput";
			this.Column11.Name = "Column11";
			this.Column11.ReadOnly = true;
			this.Column11.Visible = false;
			this.Column14.DataPropertyName = "ObjectID";
			this.Column14.HeaderText = "PID";
			this.Column14.Name = "Column14";
			this.Column14.ReadOnly = true;
			this.Column14.Visible = false;
			this.Column2.DataPropertyName = "userName";
			this.Column2.HeaderText = "Column2";
			this.Column2.Name = "Column2";
			this.Column2.ReadOnly = true;
			this.Column2.Visible = false;
			this.Column3.DataPropertyName = "fullName";
			this.Column3.HeaderText = "Column3";
			this.Column3.Name = "Column3";
			this.Column3.ReadOnly = true;
			this.Column3.Visible = false;
			this.Column4.DataPropertyName = "ExecuteDate";
			this.Column4.HeaderText = "Column4";
			this.Column4.Name = "Column4";
			this.Column4.ReadOnly = true;
			this.Column4.Visible = false;
			this.groupBox3.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox3.Controls.Add(this.btnSeeAll);
			this.groupBox3.Controls.Add(this.btnObjectSearch);
			this.groupBox3.Controls.Add(this.txtObjectSearch);
			this.groupBox3.Controls.Add(this.label7);
			this.groupBox3.Controls.Add(this.label5);
			this.groupBox3.Controls.Add(this.txttoDay);
			this.groupBox3.Controls.Add(this.label6);
			this.groupBox3.Controls.Add(this.txtfromDay);
			this.groupBox3.Location = new System.Drawing.Point(160, 5);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new Size(733, 51);
			this.groupBox3.TabIndex = 40;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Tìm kiếm nhanh";
			this.btnSeeAll.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.btnSeeAll.Location = new System.Drawing.Point(645, 16);
			this.btnSeeAll.Name = "btnSeeAll";
			this.btnSeeAll.Size = new Size(80, 26);
			this.btnSeeAll.TabIndex = 5;
			this.btnSeeAll.Text = "Xem hết";
			this.btnSeeAll.UseVisualStyleBackColor = true;
			this.btnSeeAll.Click += new EventHandler(this.btnSeeAll_Click);
			this.btnObjectSearch.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.btnObjectSearch.Location = new System.Drawing.Point(562, 16);
			this.btnObjectSearch.Name = "btnObjectSearch";
			this.btnObjectSearch.Size = new Size(80, 26);
			this.btnObjectSearch.TabIndex = 4;
			this.btnObjectSearch.Text = "Tìm";
			this.btnObjectSearch.UseVisualStyleBackColor = true;
			this.btnObjectSearch.Click += new EventHandler(this.btnObjectSearch_Click);
			this.txtObjectSearch.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtObjectSearch.Font = new Font("Arial", 11.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtObjectSearch.Location = new System.Drawing.Point(378, 17);
			this.txtObjectSearch.Name = "txtObjectSearch";
			this.txtObjectSearch.Size = new Size(178, 25);
			this.txtObjectSearch.TabIndex = 3;
			this.label7.AutoSize = true;
			this.label7.Location = new System.Drawing.Point(307, 22);
			this.label7.Name = "label7";
			this.label7.Size = new Size(68, 15);
			this.label7.TabIndex = 60;
			this.label7.Text = "Đối tượng :";
			this.label5.AutoSize = true;
			this.label5.Location = new System.Drawing.Point(170, 23);
			this.label5.Name = "label5";
			this.label5.Size = new Size(28, 15);
			this.label5.TabIndex = 59;
			this.label5.Text = "đến";
			this.txttoDay.CustomFormat = "dd/MM/yyyy";
			this.txttoDay.Format = DateTimePickerFormat.Custom;
			this.txttoDay.Location = new System.Drawing.Point(201, 20);
			this.txttoDay.Name = "txttoDay";
			this.txttoDay.Size = new Size(100, 21);
			this.txttoDay.TabIndex = 2;
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(8, 23);
			this.label6.Name = "label6";
			this.label6.Size = new Size(57, 15);
			this.label6.TabIndex = 57;
			this.label6.Text = "Từ ngày :";
			this.txtfromDay.CustomFormat = "dd/MM/yyyy";
			this.txtfromDay.Format = DateTimePickerFormat.Custom;
			this.txtfromDay.Location = new System.Drawing.Point(67, 20);
			this.txtfromDay.Name = "txtfromDay";
			this.txtfromDay.Size = new Size(100, 21);
			this.txtfromDay.TabIndex = 1;
			this.txtCountItem.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.txtCountItem.BackColor = Color.FromArgb(255, 192, 255);
			this.txtCountItem.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtCountItem.Location = new System.Drawing.Point(7, 411);
			this.txtCountItem.Name = "txtCountItem";
			this.txtCountItem.ReadOnly = true;
			this.txtCountItem.Size = new Size(886, 22);
			this.txtCountItem.TabIndex = 46;
			this.txtCountItem.TextAlign = HorizontalAlignment.Right;
			this.btnDel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnDel.Enabled = false;
			this.btnDel.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnDel.FlatStyle = FlatStyle.Flat;
			this.btnDel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnDel.Location = new System.Drawing.Point(480, 567);
			this.btnDel.Name = "btnDel";
			this.btnDel.Size = new Size(124, 26);
			this.btnDel.TabIndex = 17;
			this.btnDel.Text = "Xoá hoá đơn [ F8 ]";
			this.btnDel.UseVisualStyleBackColor = true;
			this.btnDel.Click += new EventHandler(this.btnDel_Click);
			this.btnPrint.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnPrint.Enabled = false;
			this.btnPrint.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnPrint.FlatStyle = FlatStyle.Flat;
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new System.Drawing.Point(376, 567);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(102, 26);
			this.btnPrint.TabIndex = 16;
			this.btnPrint.Text = "Xem và in [ F7 ]";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnPrint_Click);
			this.btnSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnSave.Enabled = false;
			this.btnSave.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnSave.FlatStyle = FlatStyle.Flat;
			this.btnSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSave.Location = new System.Drawing.Point(246, 567);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(128, 26);
			this.btnSave.TabIndex = 13;
			this.btnSave.Text = "Lưu hoá đơn [ F6 ]";
			this.btnSave.UseVisualStyleBackColor = true;
			this.btnSave.Click += new EventHandler(this.btnSave_Click);
			this.btnEdit.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnEdit.Enabled = false;
			this.btnEdit.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnEdit.FlatStyle = FlatStyle.Flat;
			this.btnEdit.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnEdit.Location = new System.Drawing.Point(121, 567);
			this.btnEdit.Name = "btnEdit";
			this.btnEdit.Size = new Size(123, 26);
			this.btnEdit.TabIndex = 15;
			this.btnEdit.Text = "Sửa hoá đơn [ F5 ]";
			this.btnEdit.UseVisualStyleBackColor = true;
			this.btnEdit.Click += new EventHandler(this.btnEdit_Click);
			this.btnAdd.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnAdd.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnAdd.FlatStyle = FlatStyle.Flat;
			this.btnAdd.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnAdd.Location = new System.Drawing.Point(7, 567);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new Size(112, 26);
			this.btnAdd.TabIndex = 14;
			this.btnAdd.Text = "Thêm mới [ F4 ]";
			this.btnAdd.UseVisualStyleBackColor = true;
			this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
			this.groupBox1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.Controls.Add(this.lblFullNameInOut);
			this.groupBox1.Controls.Add(this.dtpExecuteDate);
			this.groupBox1.Controls.Add(this.txtFullName);
			this.groupBox1.Controls.Add(this.lblDayInOut);
			this.groupBox1.Controls.Add(this.label8);
			this.groupBox1.Controls.Add(this.dtpTimeBill);
			this.groupBox1.Controls.Add(this.txtNote);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.txtMoney);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.btnSearch);
			this.groupBox1.Controls.Add(this.txtName);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.txtID);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox1.Location = new System.Drawing.Point(7, 434);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(886, 126);
			this.groupBox1.TabIndex = 52;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thông tin về hoá đơn";
			this.lblFullNameInOut.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.lblFullNameInOut.Location = new System.Drawing.Point(220, 91);
			this.lblFullNameInOut.Name = "lblFullNameInOut";
			this.lblFullNameInOut.Size = new Size(70, 15);
			this.lblFullNameInOut.TabIndex = 63;
			this.lblFullNameInOut.Text = "Người thu :";
			this.lblFullNameInOut.TextAlign = ContentAlignment.MiddleRight;
			this.dtpExecuteDate.CustomFormat = "dd/MM/yyyy";
			this.dtpExecuteDate.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dtpExecuteDate.Format = DateTimePickerFormat.Custom;
			this.dtpExecuteDate.Location = new System.Drawing.Point(76, 89);
			this.dtpExecuteDate.Name = "dtpExecuteDate";
			this.dtpExecuteDate.Size = new Size(100, 21);
			this.dtpExecuteDate.TabIndex = 62;
			this.dtpExecuteDate.KeyPress += new KeyPressEventHandler(this.dtpExecuteDate_KeyPress);
			this.txtFullName.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtFullName.BackColor = Color.White;
			this.txtFullName.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtFullName.ForeColor = Color.Black;
			this.txtFullName.Location = new System.Drawing.Point(293, 89);
			this.txtFullName.Name = "txtFullName";
			this.txtFullName.ReadOnly = true;
			this.txtFullName.Size = new Size(578, 21);
			this.txtFullName.TabIndex = 60;
			this.txtFullName.KeyPress += new KeyPressEventHandler(this.txtFullName_KeyPress);
			this.lblDayInOut.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.lblDayInOut.Location = new System.Drawing.Point(3, 92);
			this.lblDayInOut.Name = "lblDayInOut";
			this.lblDayInOut.Size = new Size(70, 15);
			this.lblDayInOut.TabIndex = 61;
			this.lblDayInOut.Text = "Ngày thu :";
			this.lblDayInOut.TextAlign = ContentAlignment.MiddleRight;
			this.label8.AutoSize = true;
			this.label8.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label8.Location = new System.Drawing.Point(229, 37);
			this.label8.Name = "label8";
			this.label8.Size = new Size(61, 15);
			this.label8.TabIndex = 59;
			this.label8.Text = "Ngày lập :";
			this.dtpTimeBill.CustomFormat = "dd/MM/yyyy";
			this.dtpTimeBill.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dtpTimeBill.Format = DateTimePickerFormat.Custom;
			this.dtpTimeBill.Location = new System.Drawing.Point(293, 34);
			this.dtpTimeBill.Name = "dtpTimeBill";
			this.dtpTimeBill.Size = new Size(100, 21);
			this.dtpTimeBill.TabIndex = 8;
			this.dtpTimeBill.KeyPress += new KeyPressEventHandler(this.dtpTimeBill_KeyPress);
			this.txtNote.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtNote.BackColor = Color.White;
			this.txtNote.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtNote.Location = new System.Drawing.Point(293, 61);
			this.txtNote.Name = "txtNote";
			this.txtNote.ReadOnly = true;
			this.txtNote.Size = new Size(578, 21);
			this.txtNote.TabIndex = 12;
			this.txtNote.KeyPress += new KeyPressEventHandler(this.txtNote_KeyPress);
			this.label4.AutoSize = true;
			this.label4.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label4.Location = new System.Drawing.Point(235, 64);
			this.label4.Name = "label4";
			this.label4.Size = new Size(55, 15);
			this.label4.TabIndex = 51;
			this.label4.Text = "Ghi chú :";
			this.txtMoney.BackColor = Color.White;
			this.txtMoney.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtMoney.ForeColor = Color.Blue;
			this.txtMoney.Location = new System.Drawing.Point(76, 61);
			this.txtMoney.Name = "txtMoney";
			this.txtMoney.ReadOnly = true;
			this.txtMoney.Size = new Size(146, 21);
			this.txtMoney.TabIndex = 11;
			this.txtMoney.TextAlign = HorizontalAlignment.Right;
			this.txtMoney.KeyPress += new KeyPressEventHandler(this.txtMoney_KeyPress);
			this.label3.AutoSize = true;
			this.label3.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label3.Location = new System.Drawing.Point(22, 64);
			this.label3.Name = "label3";
			this.label3.Size = new Size(51, 15);
			this.label3.TabIndex = 49;
			this.label3.Text = "Số tiền :";
			this.btnSearch.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.btnSearch.Enabled = false;
			this.btnSearch.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.btnSearch.Location = new System.Drawing.Point(804, 30);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new Size(67, 26);
			this.btnSearch.TabIndex = 10;
			this.btnSearch.Text = "Tìm [ F2 ]";
			this.btnSearch.UseVisualStyleBackColor = true;
			this.btnSearch.Click += new EventHandler(this.btnSearch_Click);
			this.txtName.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtName.BackColor = Color.White;
			this.txtName.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtName.Location = new System.Drawing.Point(482, 33);
			this.txtName.Name = "txtName";
			this.txtName.ReadOnly = true;
			this.txtName.Size = new Size(316, 21);
			this.txtName.TabIndex = 9;
			this.txtName.KeyPress += new KeyPressEventHandler(this.txtName_KeyPress);
			this.label2.AutoSize = true;
			this.label2.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label2.Location = new System.Drawing.Point(411, 36);
			this.label2.Name = "label2";
			this.label2.Size = new Size(68, 15);
			this.label2.TabIndex = 2;
			this.label2.Text = "Đối tượng :";
			this.txtID.BackColor = Color.White;
			this.txtID.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtID.Location = new System.Drawing.Point(76, 33);
			this.txtID.Name = "txtID";
			this.txtID.ReadOnly = true;
			this.txtID.Size = new Size(146, 21);
			this.txtID.TabIndex = 7;
			this.txtID.TextChanged += new EventHandler(this.txtID_TextChanged);
			this.label1.AutoSize = true;
			this.label1.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label1.Location = new System.Drawing.Point(18, 36);
			this.label1.Name = "label1";
			this.label1.Size = new Size(55, 15);
			this.label1.TabIndex = 0;
			this.label1.Text = "Số hiệu :";
			this.lblType.BorderStyle = BorderStyle.Fixed3D;
			this.lblType.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.lblType.ForeColor = Color.Blue;
			this.lblType.Location = new System.Drawing.Point(7, 12);
			this.lblType.Name = "lblType";
			this.lblType.Size = new Size(147, 44);
			this.lblType.TabIndex = 53;
			this.lblType.Text = "- : -";
			this.lblType.TextAlign = ContentAlignment.MiddleCenter;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.lblType);
			base.Controls.Add(this.groupBox1);
			base.Controls.Add(this.btnDel);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.btnEdit);
			base.Controls.Add(this.btnAdd);
			base.Controls.Add(this.txtCountItem);
			base.Controls.Add(this.groupBox3);
			base.Controls.Add(this.dgvBill);
			base.Controls.Add(this.btnClose);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmInOutMoneyBill";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "HOÁ ĐƠN";
			base.WindowState = FormWindowState.Maximized;
			base.Load += new EventHandler(this.frmInput_Load);
			((ISupportInitialize)this.dgvBill).EndInit();
			this.groupBox3.ResumeLayout(false);
			this.groupBox3.PerformLayout();
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public frmInOutMoneyBill()
		{
			this.InitializeComponent();
		}
		private void frmInput_Load(object sender, EventArgs e)
		{
			if (this.Type == "IN")
			{
				this.lblType.Text = "PHIẾU THU";
				this.lblDayInOut.Text = "Ngày thu :";
				this.lblFullNameInOut.Text = "Người thu :";
			}
			else
			{
				this.lblType.Text = "PHIẾU CHI";
				this.lblDayInOut.Text = "Ngày chi :";
				this.lblFullNameInOut.Text = "Người chi :";
			}
			this.txtFullName.Text = this.fullName;
			this.getBill();
			this.noAllowOtherEditBill = this.objFunc.getNoAllowOtherEditBill();
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void btnPrint_Click(object sender, EventArgs e)
		{
			new frmInOutMoneyBillView
			{
				billID = this.txtID.Text,
				billDate = this.dtpTimeBill.Text,
				objectName = this.txtName.Text,
				objectID = this.currObjectID,
				billNote = this.txtNote.Text,
				billExecute = string.Concat(new string[]
				{
					"Ngày ",
					this.dtpExecuteDate.Value.Day.ToString(),
					" tháng ",
					this.dtpExecuteDate.Value.Month.ToString(),
					" năm ",
					this.dtpExecuteDate.Value.Year.ToString()
				}),
				billMoney = this.txtMoney.Text,
				BillOwnerCreater = this.txtFullName.Text,
				typeBill = this.Type,
				billMoneyAsWord = this.objFunc.changeNumberToWord1(long.Parse(this.txtMoney.Text))
			}.ShowDialog();
			this.objInOutBill.setPrinted(this.txtID.Text);
		}
		private void btnAdd_Click(object sender, EventArgs e)
		{
			this.txtID.Text = "";
			this.txtName.Text = "";
			this.txtMoney.Text = "0";
			this.txtNote.Text = "";
			this.txtMoney.ReadOnly = false;
			this.txtNote.ReadOnly = false;
			this.btnSearch.Enabled = true;
			this.btnSave.Enabled = true;
			this.btnDel.Enabled = false;
			this.btnPrint.Enabled = false;
			this.dtpTimeBill.Enabled = true;
			this.btnSearch.Focus();
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
			if (this.txtID.Text == "")
			{
				string outBillID = this.objInOutBill.getOutBillID(this.Type);
				this.txtID.Text = outBillID;
			}
			if (this.objInOutBill.action(this.txtID.Text, this.dtpTimeBill.Value, double.Parse(this.txtMoney.Text), this.Type, this.txtNote.Text, this.currObjectID, this.txtName.Text, this.userName, this.fullName, this.dtpExecuteDate.Value) == 1)
			{
				MessageBox.Show("Có lỗi xảy ra trong quá trình lưu hoá đơn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.txtID.Focus();
			}
			else
			{
				this.getBill();
				this.btnEdit.Enabled = true;
				this.btnPrint.Enabled = true;
				this.btnDel.Enabled = true;
				this.btnSave.Enabled = false;
				this.btnSearch.Enabled = false;
				this.dtpExecuteDate.Enabled = false;
			}
		}
		private void getBill()
		{
			this.txtID.Text = "";
			this.txtName.Text = "";
			this.txtMoney.Text = "0";
			this.txtNote.Text = "";
			this.dgvBill.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			string cmdText = string.Concat(new object[]
			{
				"SELECT * FROM [TabInOutBill] WHERE TypeInput IN ('",
				this.Type,
				"') AND datepart(Month,CreateDate) = ",
				DateTime.Now.Month,
				" AND datepart(Year,CreateDate) = ",
				DateTime.Now.Year.ToString(),
				" ORDER BY [CreateDate] DESC"
			});
			SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			sqlConnection.Open();
			sqlDataAdapter.Fill(dataSet);
			this.dgvBill.DataSource = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
			sqlDataAdapter.Dispose();
			dataSet.Dispose();
			if (this.dgvBill.Rows.Count > 0)
			{
				this.txtCountItem.Text = "Tìm thấy " + this.dgvBill.Rows.Count.ToString() + " hoá đơn trên hệ thống";
			}
			else
			{
				this.txtCountItem.Text = "Không tìm thấy hoá đơn nào trên hệ thống";
			}
		}
		private void getBillBySearch()
		{
			try
			{
				this.dgvBill.AutoGenerateColumns = false;
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				string text = "";
				if (this.txtObjectSearch.Text.Trim() != "")
				{
					text = string.Concat(new string[]
					{
						" AND ([TabInOutBill].[ObjectName] LIKE N'%",
						this.txtObjectSearch.Text.Trim().ToUpper(),
						"%' OR Upper([TabInOutBill].[ObjectName]) LIKE N'%",
						this.txtObjectSearch.Text.Trim().ToUpper(),
						"%')"
					});
				}
				string cmdText = string.Concat(new string[]
				{
					"SELECT * FROM [TabInOutBill] WHERE TypeInput IN ('",
					this.Type,
					"') ",
					text,
					" AND [TabInOutBill].[CreateDate] BETWEEN @objDate1 AND @objDate2 ORDER BY [CreateDate] DESC"
				});
				SqlParameter sqlParameter = new SqlParameter("objDate1", SqlDbType.DateTime);
				SqlParameter sqlParameter2 = new SqlParameter("objDate2", SqlDbType.DateTime);
				sqlParameter.Value = DateTime.Parse(this.txtfromDay.Value.ToString().Substring(0, 10) + " 00:00:00 AM");
				sqlParameter2.Value = DateTime.Parse(this.txttoDay.Value.ToString().Substring(0, 10) + " 11:59:59 PM");
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(new SqlCommand(cmdText, sqlConnection)
				{
					Parameters = 
					{
						sqlParameter,
						sqlParameter2
					}
				});
				DataSet dataSet = new DataSet();
				sqlConnection.Open();
				sqlDataAdapter.Fill(dataSet);
				this.dgvBill.DataSource = dataSet.Tables[0];
				sqlConnection.Close();
				sqlConnection.Dispose();
				sqlDataAdapter.Dispose();
				dataSet.Dispose();
				if (this.dgvBill.Rows.Count > 0)
				{
					this.txtCountItem.Text = "Tìm thấy " + this.dgvBill.Rows.Count.ToString() + " hoá đơn trên hệ thống";
				}
				else
				{
					this.txtCountItem.Text = "Không tìm thấy hoá đơn nào trên hệ thống";
				}
			}
			catch
			{
			}
		}
		private void btnSearch_Click(object sender, EventArgs e)
		{
			try
			{
				frmSelectObjectIn frmSelectObjectIn = new frmSelectObjectIn();
				frmSelectObjectIn.TypeObject = this.Type;
				frmSelectObjectIn.ShowDialog();
				this.currObjectID = frmSelectObjectIn.objectID;
				this.txtName.Text = frmSelectObjectIn.objectName;
				this.txtMoney.Text = frmSelectObjectIn.objectValue;
				this.txtMoney.Focus();
			}
			catch
			{
			}
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			if (!this.noAllowOtherEditBill || (this.noAllowOtherEditBill && this.objInOutBill.getuserNameBillID(this.txtID.Text) == this.userName))
			{
				bool noEditAffterPrint = this.objFunc.getNoEditAffterPrint();
				if (!noEditAffterPrint || (noEditAffterPrint && !this.objInOutBill.getPrinted(this.txtID.Text)))
				{
					this.txtMoney.ReadOnly = false;
					this.txtNote.ReadOnly = false;
					this.btnSave.Enabled = true;
					this.btnSearch.Enabled = true;
					this.dtpTimeBill.Enabled = false;
					this.dtpExecuteDate.Enabled = true;
				}
				else
				{
					MessageBox.Show("Hoá đơn này đã được in! Bạn không thể sửa đổi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			else
			{
				MessageBox.Show("Chỉ có người tạo ra hoá đơn mới có quyền sửa đổi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}
		private void dgvBill_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			this.txtMoney.ReadOnly = true;
			this.txtNote.ReadOnly = true;
			this.btnSave.Enabled = false;
			this.dtpTimeBill.Enabled = false;
			try
			{
				if (e.RowIndex != -1)
				{
					this.currObjectID = this.dgvBill.Rows[e.RowIndex].Cells[6].Value.ToString();
					this.txtID.Text = this.dgvBill.Rows[e.RowIndex].Cells[1].Value.ToString();
					this.txtName.Text = this.dgvBill.Rows[e.RowIndex].Cells[2].Value.ToString();
					this.txtMoney.Text = this.dgvBill.Rows[e.RowIndex].Cells[3].Value.ToString();
					this.txtNote.Text = this.dgvBill.Rows[e.RowIndex].Cells[4].Value.ToString();
					this.dtpTimeBill.Value = DateTime.Parse(this.dgvBill.Rows[e.RowIndex].Cells[0].Value.ToString());
				}
			}
			catch
			{
			}
		}
		private void txtID_TextChanged(object sender, EventArgs e)
		{
			if (this.txtID.Text != "")
			{
				this.btnEdit.Enabled = true;
				this.btnPrint.Enabled = true;
				this.btnDel.Enabled = true;
			}
		}
		private void dgvBill_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			this.txtMoney.ReadOnly = true;
			this.txtNote.ReadOnly = true;
			this.btnSave.Enabled = false;
			this.dtpTimeBill.Enabled = false;
			this.dtpExecuteDate.Enabled = false;
			try
			{
				if (e.RowIndex != -1)
				{
					this.currObjectID = this.dgvBill.Rows[e.RowIndex].Cells[6].Value.ToString();
					this.txtID.Text = this.dgvBill.Rows[e.RowIndex].Cells[1].Value.ToString();
					this.txtName.Text = this.dgvBill.Rows[e.RowIndex].Cells[2].Value.ToString();
					this.txtMoney.Text = this.dgvBill.Rows[e.RowIndex].Cells[3].Value.ToString();
					this.txtNote.Text = this.dgvBill.Rows[e.RowIndex].Cells[4].Value.ToString();
					this.currUserName = this.dgvBill.Rows[e.RowIndex].Cells["Column2"].Value.ToString();
					this.txtFullName.Text = this.dgvBill.Rows[e.RowIndex].Cells["Column3"].Value.ToString();
					this.dtpTimeBill.Value = DateTime.Parse(this.dgvBill.Rows[e.RowIndex].Cells[0].Value.ToString());
					this.dtpExecuteDate.Value = DateTime.Parse(this.dgvBill.Rows[e.RowIndex].Cells["Column4"].Value.ToString());
				}
			}
			catch
			{
			}
		}
		private void btnSeeAll_Click(object sender, EventArgs e)
		{
			this.getBill();
		}
		private void btnObjectSearch_Click(object sender, EventArgs e)
		{
			this.txtID.Text = "";
			this.txtName.Text = "";
			this.txtMoney.Text = "0";
			this.txtNote.Text = "";
			this.getBillBySearch();
		}
		private void btnDel_Click(object sender, EventArgs e)
		{
			if (MessageBox.Show("Bạn có chắc chắn muốn xoá hoá đơn [ " + this.txtID.Text.ToUpper() + " ] không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
			{
				this.objInOutBill.delItem(this.txtID.Text);
				this.getBill();
			}
		}
		private void dtpTimeBill_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.txtName.Focus();
			}
		}
		private void txtName_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.btnSearch.Focus();
			}
		}
		private void txtMoney_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.txtNote.Focus();
			}
		}
		private void txtNote_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.dtpExecuteDate.Focus();
			}
		}
		private void dtpExecuteDate_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.txtFullName.Focus();
			}
		}
		private void txtFullName_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r' && this.btnSave.Enabled)
			{
				this.btnSave.PerformClick();
			}
			else
			{
				if (e.KeyChar == '\r')
				{
					this.dgvBill.Focus();
				}
			}
		}
	}
}
